]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
util: Add createTimeLabel()
authorFlorian Müllner <fmuellner@gnome.org>
Wed, 25 Feb 2015 22:23:49 +0000 (23:23 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Wed, 4 Mar 2015 12:55:01 +0000 (13:55 +0100)
On locales that support it, time formats should follow the 12-hour/24-hour
preference, which implies that they should be updated when the setting
changes. So add another utility method which creates a label for a specific
time and keeps it in sync with the format setting.

https://bugzilla.gnome.org/show_bug.cgi?id=745111

js/misc/util.js

index c938fdcbd1b86635fc855f25db46f98324ed82f4..748c7b7d5b7b895701ef72d82fae48959956ab6a 100644 (file)
@@ -246,6 +246,20 @@ function formatTime(time, params) {
     return date.format(Shell.util_translate_time_string(format));
 }
 
+function createTimeLabel(date, params) {
+    if (_desktopSettings == null)
+        _desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
+
+    let label = new St.Label({ text: formatTime(date, params) });
+    let id = _desktopSettings.connect('changed::clock-format', function() {
+        label.text = formatTime(date, params);
+    });
+    label.connect('destroy', function() {
+        _desktopSettings.disconnect(id);
+    });
+    return label;
+}
+
 // lowerBound:
 // @array: an array or array-like object, already sorted
 //         according to @cmp